#include <iostream>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <pthread.h>

#include <unistd.h>
#include "module.h"
#include "mutexs.h"
#include "model_process.h"
#include "object_detect.h"
#include "utils.h"



struct jpg_buf_t *jpg = NULL;

pthread_t cam_tid;
pthread_t zgb_tid;
pthread_t srv_tid;

pthread_mutex_t cam_mutex;
pthread_mutex_t send_mutex;
int sync_flag = 3;


int main(int argc, char *argv[])
{
	int srv_ret = -1, cam_ret = -1, zgb_ret = -1;
	pthread_mutex_init(&cam_mutex, NULL);
	pthread_mutex_init(&send_mutex, NULL);
	/* acl thread */
	while (cam_ret < 0)
	{
		cam_ret = pthread_create(&cam_tid, NULL, thread_acl, NULL);
		if (cam_ret)
		{
			errno = cam_ret;
			perror("create acl thread");
			exit(EXIT_FAILURE);
		}
		else
			printf("create acl thread success\n");
		cam_ret = pthread_detach(cam_tid);
		if (cam_ret)
		{
			errno = cam_ret;
			perror("detach acl thread");
			exit(EXIT_FAILURE);
		}
		else
			printf("detach acl thread success\n");
	}

	/* android server thread */
	while (srv_ret < 0)
	{
		srv_ret = pthread_create(&srv_tid, NULL, thread_srv, NULL);
		if (srv_ret)
		{
			errno = srv_ret;
			perror("create android server thread\n");
			exit(EXIT_FAILURE);
		}
		else
			printf("create android server thread success\n");

		srv_ret = pthread_detach(srv_tid);
		if (srv_ret)
		{
			errno = srv_ret;
			perror("deta`ch android server thread\n");
			exit(EXIT_FAILURE);
		}
		else
			printf("detach android server thread success\n");
	}

	/* main thread, process environment data form m0 board or process short message */
	while (1)
	{
		// pthread_mutex_destroy(&cam_mutex);
	}
	exit(EXIT_SUCCESS);
}
